﻿using Little.Soldier.SWIFT;
using Little.Soldier.SWIFT.Definition;
using System;
using System.ComponentModel;
using System.Globalization;
using System.Text;

namespace Little.Soldier.SWIFT.Messages.Category0
{
  public class MTS22 : SwiftMessage
  {
    private static SwiftMessageDefinition MessageDefinition;
    private static SwiftTagDefinition U0002;
    private static SwiftTagSubItemDefinition U0003;
    private static SwiftTagDefinition U0004;
    private static SwiftTagSubItemDefinition U0005;
    private static SwiftTagDefinition U0006;
    private static SwiftTagSubItemDefinition U0007;
    private static SwiftTagSubItemDefinition U0008;
    private static SwiftTagDefinition U000E;
    private static SwiftTagSubItemDefinition U000F;
    private static SwiftTagChoiceDefinition U0010;
    private static SwiftTagDefinition U0011;
    private static SwiftTagSubItemDefinition U0012;
    private static SwiftTagSubItemDefinition U0013;
    private static SwiftTagSubItemDefinition U0014;
    private static SwiftTagSubItemDefinition U0015;
    private static SwiftTagSubItemDefinition U0016;
    private static SwiftTagSubItemDefinition U0017;
    private static SwiftTagSubItemDefinition U0018;
    private static SwiftTagSubItemDefinition U0019;
    private static SwiftTagDefinition U001A;
    private static SwiftTagSubItemDefinition U001B;
    private static SwiftTagSubItemDefinition U001C;
    private static SwiftTagSubItemDefinition U001D;
    private static SwiftTagSubItemDefinition U001E;
    private static SwiftTagSubItemDefinition U001F;
    private static SwiftTagSubItemDefinition U007F;

    [Description("System Authentication")]
    public Tag502 SystemAuthentication_502
    {
      get
      {
        return new Tag502((SwiftElement) this, 0, (SwiftDefinitionElement) MTS22.U0002);
      }
    }

    [Description("System Authentication")]
    public Tag502 Tag502_SystemAuthentication
    {
      get
      {
        return this.SystemAuthentication_502;
      }
    }

    [Description("Session Number")]
    public Tag151 SessionNumber_151
    {
      get
      {
        return new Tag151((SwiftElement) this, 0, (SwiftDefinitionElement) MTS22.U0004);
      }
    }

    [Description("Session Number")]
    public Tag151 Tag151_SessionNumber
    {
      get
      {
        return this.SessionNumber_151;
      }
    }

    [Description("Date-Time")]
    public Tag177 DateTime_177
    {
      get
      {
        return new Tag177((SwiftElement) this, 0, (SwiftDefinitionElement) MTS22.U0006);
      }
    }

    [Description("Date-Time")]
    public Tag177 Tag177_DateTime
    {
      get
      {
        return this.DateTime_177;
      }
    }

    [Description("Window Size")]
    public MTS22.Tag110 WindowSize_110
    {
      get
      {
        return new MTS22.Tag110((SwiftElement) this, 0, (SwiftDefinitionElement) MTS22.U000E);
      }
    }

    [Description("Window Size")]
    public MTS22.Tag110 Tag110_WindowSize
    {
      get
      {
        return this.WindowSize_110;
      }
    }

    [Description("previous-session-info")]
    public MTS22.Tag333 PreviousSessionInformation_333
    {
      get
      {
        return new MTS22.Tag333((SwiftElement) this, 0, (SwiftDefinitionElement) MTS22.U0011);
      }
    }

    [Description("previous-session-info")]
    public MTS22.Tag333 Tag333_PreviousSessionInformation
    {
      get
      {
        return this.PreviousSessionInformation_333;
      }
    }

    [Description("current-sessioninfo")]
    public Tag330 CurrentSessionInformation_330
    {
      get
      {
        return new Tag330((SwiftElement) this, 0, (SwiftDefinitionElement) MTS22.U001A);
      }
    }

    [Description("current-sessioninfo")]
    public Tag330 Tag330_CurrentSessionInformation
    {
      get
      {
        return this.CurrentSessionInformation_330;
      }
    }

    public MTS22()
      : base(true)
    {
    }

    public MTS22(SwiftMessage message)
      : base(message)
    {
    }

    internal override SwiftMessageDefinition MsgDefinition()
    {
      return MTS22.MessageDefinition;
    }

    protected override void InitSwiftMessageDefinition()
    {
      MTS22.MessageDefinition = new SwiftMessageDefinition("MTS22", "Login Positive Acknowledgement (LAK)");
      MTS22.U0002 = new SwiftTagDefinition("SystemAuthentication_502", "System Authentication");
      MTS22.U0002.TagName = "{502:";
      MTS22.U0003 = new SwiftTagSubItemDefinition("SystemAuthentication", "System Authentication");
      MTS22.U0002.Elements.Add((SwiftDefinitionElement) MTS22.U0003);
      MTS22.MessageDefinition.Elements.Add((SwiftDefinitionElement) MTS22.U0002);
      MTS22.U0004 = new SwiftTagDefinition("SessionNumber_151", "Session Number");
      MTS22.U0004.TagName = "{151:";
      MTS22.U0005 = new SwiftTagSubItemDefinition("SessionNumber", "Session Number");
      MTS22.U0004.Elements.Add((SwiftDefinitionElement) MTS22.U0005);
      MTS22.MessageDefinition.Elements.Add((SwiftDefinitionElement) MTS22.U0004);
      MTS22.U0006 = new SwiftTagDefinition("DateTime_177", "Date-Time");
      MTS22.U0006.TagName = "{177:";
      MTS22.U0007 = new SwiftTagSubItemDefinition("Date", "Date");
      MTS22.U0006.Elements.Add((SwiftDefinitionElement) MTS22.U0007);
      MTS22.U0008 = new SwiftTagSubItemDefinition("Time", "Time");
      MTS22.U0006.Elements.Add((SwiftDefinitionElement) MTS22.U0008);
      MTS22.MessageDefinition.Elements.Add((SwiftDefinitionElement) MTS22.U0006);
      MTS22.U000E = new SwiftTagDefinition("WindowSize_110", "Window Size");
      MTS22.U000E.TagName = "{110:";
      MTS22.U000F = new SwiftTagSubItemDefinition("WindowSize", "Window Size");
      MTS22.U000E.Elements.Add((SwiftDefinitionElement) MTS22.U000F);
      MTS22.MessageDefinition.Elements.Add((SwiftDefinitionElement) MTS22.U000E);
      MTS22.U0010 = new SwiftTagChoiceDefinition("Choice", "");
      MTS22.U0010.Mandatory = false;
      MTS22.U0010.Multiple = true;
      MTS22.U0011 = new SwiftTagDefinition("PreviousSessionInformation_333", "previous-session-info");
      MTS22.U0011.TagName = "{333:";
      MTS22.U0012 = new SwiftTagSubItemDefinition("DateLastSessionOpened", "Date Last Session Opened");
      MTS22.U0011.Elements.Add((SwiftDefinitionElement) MTS22.U0012);
      MTS22.U0013 = new SwiftTagSubItemDefinition("TimeLastSessionOpened", "Time Last Session Opened");
      MTS22.U0011.Elements.Add((SwiftDefinitionElement) MTS22.U0013);
      MTS22.U0014 = new SwiftTagSubItemDefinition("SessionNumber", "Session Number");
      MTS22.U0011.Elements.Add((SwiftDefinitionElement) MTS22.U0014);
      MTS22.U0015 = new SwiftTagSubItemDefinition("DateLastSessionClosed", "Date Last Session Closed");
      MTS22.U0011.Elements.Add((SwiftDefinitionElement) MTS22.U0015);
      MTS22.U0016 = new SwiftTagSubItemDefinition("TimeLastSessionClosed", "Time Last Session Closed");
      MTS22.U0011.Elements.Add((SwiftDefinitionElement) MTS22.U0016);
      MTS22.U0017 = new SwiftTagSubItemDefinition("ErrorCode", "Reason For Closure");
      MTS22.U0011.Elements.Add((SwiftDefinitionElement) MTS22.U0017);
      MTS22.U0018 = new SwiftTagSubItemDefinition("ISN", "Last ISN Received");
      MTS22.U0011.Elements.Add((SwiftDefinitionElement) MTS22.U0018);
      MTS22.U0019 = new SwiftTagSubItemDefinition("OSN", "Last OSN Sent");
      MTS22.U0011.Elements.Add((SwiftDefinitionElement) MTS22.U0019);
      MTS22.U0010.Elements.Add((SwiftDefinitionElement) MTS22.U0011);
      MTS22.U001A = new SwiftTagDefinition("CurrentSessionInformation_330", "current-sessioninfo");
      MTS22.U001A.TagName = "{330:";
      MTS22.U001B = new SwiftTagSubItemDefinition("SessionNumber", "Session Number");
      MTS22.U001A.Elements.Add((SwiftDefinitionElement) MTS22.U001B);
      MTS22.U001C = new SwiftTagSubItemDefinition("ISN", "Isn");
      MTS22.U001A.Elements.Add((SwiftDefinitionElement) MTS22.U001C);
      MTS22.U001D = new SwiftTagSubItemDefinition("ISNNAK", "Isnnak");
      MTS22.U001A.Elements.Add((SwiftDefinitionElement) MTS22.U001D);
      MTS22.U001E = new SwiftTagSubItemDefinition("OSN", "Osn");
      MTS22.U001A.Elements.Add((SwiftDefinitionElement) MTS22.U001E);
      MTS22.U001F = new SwiftTagSubItemDefinition("OSNNAK", "Osnnak");
      MTS22.U001A.Elements.Add((SwiftDefinitionElement) MTS22.U001F);
      MTS22.U007F = new SwiftTagSubItemDefinition("AckReplayIndicator", "Ack-Replay-Indicator");
      MTS22.U001A.Elements.Add((SwiftDefinitionElement) MTS22.U007F);
      MTS22.U0010.Elements.Add((SwiftDefinitionElement) MTS22.U001A);
      MTS22.MessageDefinition.Elements.Add((SwiftDefinitionElement) MTS22.U0010);
    }

    public class Tag110 : SwiftTagWrapper
    {
      public string Value
      {
        get
        {
          return this.GetValue();
        }
        set
        {
          this.SetValue("110", value);
        }
      }

      internal Tag110(SwiftElement parent, int index, SwiftDefinitionElement definition)
        : base(parent, index, definition)
      {
      }
    }

    public class Tag333 : SwiftTagWrapper
    {
      public string Value
      {
        get
        {
          return this.GetValue();
        }
        set
        {
          this.SetValue("333", value);
        }
      }

      public DateTime DateLastSessionOpened
      {
        get
        {
          DateTime result = DateTime.MinValue;
          string str = this.Value;
          if (str != null && str.Length > 0)
            DateTime.TryParseExact(str.Length <= 6 ? str.Substring(0) : str.Substring(0, 6), "yyMMdd", (IFormatProvider) CultureInfo.CurrentCulture, DateTimeStyles.None, out result);
          return result;
        }
        set
        {
          int num1 = 0;
          int num2 = 6;
          StringBuilder stringBuilder = new StringBuilder();
          string str1 = this.Value ?? string.Empty;
          str1.PadLeft(num1, ' ');
          stringBuilder.Append(str1.Substring(0, num1));
          string str2 = string.Format("{0:yyMMdd}", (object) value);
          if (str2.Length > num2)
            str2 = str2.Substring(0, num2);
          if (str1.Length > num1 + num2)
            str2 = str2.PadLeft(num2, ' ');
          stringBuilder.Append(str2);
          if (str1.Length > num1 + num2)
            stringBuilder.Append(str1.Substring(num1 + num2));
          this.Value = ((object) stringBuilder).ToString();
        }
      }

      public DateTime DateLastSessionClosed
      {
        get
        {
          DateTime result = DateTime.MinValue;
          string str = this.Value;
          if (str != null && str.Length > 14)
            DateTime.TryParseExact(str.Length <= 20 ? str.Substring(14) : str.Substring(14, 6), "yyMMdd", (IFormatProvider) CultureInfo.CurrentCulture, DateTimeStyles.None, out result);
          return result;
        }
        set
        {
          int num1 = 14;
          int num2 = 6;
          StringBuilder stringBuilder = new StringBuilder();
          string str1 = this.Value ?? string.Empty;
          str1.PadLeft(num1, ' ');
          stringBuilder.Append(str1.Substring(0, num1));
          string str2 = string.Format("{0:yyMMdd}", (object) value);
          if (str2.Length > num2)
            str2 = str2.Substring(0, num2);
          if (str1.Length > num1 + num2)
            str2 = str2.PadLeft(num2, ' ');
          stringBuilder.Append(str2);
          if (str1.Length > num1 + num2)
            stringBuilder.Append(str1.Substring(num1 + num2));
          this.Value = ((object) stringBuilder).ToString();
        }
      }

      internal Tag333(SwiftElement parent, int index, SwiftDefinitionElement definition)
        : base(parent, index, definition)
      {
      }
    }
  }
}
